﻿@using OA.Model;
@model SynergyForm
@{

    ViewBag.Title = Model.Name;

    CustomFormExtendInfo infoCustomFormExtendInfo = ViewBag.CustomFormExtendInfo;

    TableValues infoTableValues = ViewBag.TableValues;
    Dictionary<string, string> dicExtend = ViewBag.DicExtend;

    Layout = "~/Areas/Member/Views/Shared/_Layout.cshtml";
    string msg = ViewBag.Msg;
    string tips = string.Empty;
    if (!string.IsNullOrWhiteSpace(msg))
    {
        tips = $"layer.msg('{msg}');";
    }
}

<style type="text/css">
    .delete {
        cursor: pointer;
    }
</style>
<style type="text/css">
     .my_p{height:38px;line-height:38px;}
</style>
<div class="layui-my-content">
    <div class="myForm">
        @using (Html.BeginForm(FormMethod.Post, htmlAttributes: new { @class = "layui-form", id = "myForm" }))
        {
            @Html.AntiForgeryToken()

            <div class="layui-form-item">
                @Html.LabelFor(model => model.Name, new { @class = "layui-form-label" })
                <div class="layui-input-block">
                  <p class="my_p">@Model.Name</p>
                </div>
            </div>
            if (infoCustomFormExtendInfo != null && infoCustomFormExtendInfo.ListExtendField.Count > 0)
            {
                foreach (var item in infoCustomFormExtendInfo.ListExtendField)
                {
                    if (dicExtend.ContainsKey(item.Attribute))
                    {
                        item.Value = dicExtend[item.Attribute];
                    }
                    <div class="layui-form-item">
                        <label class="layui-form-label" for="@item.Attribute">@item.Name</label>
                        <div class="layui-input-block">
                            <p class="my_p">@item.Value</p>
                        </div>
                    </div>
                }

            }

            if (infoCustomFormExtendInfo != null && infoCustomFormExtendInfo.TableFields.Count > 0)
            {
                var parents = infoCustomFormExtendInfo.TableFields.Where(m => !string.IsNullOrWhiteSpace(m.ParentName)).ToList();
                var myGroups = parents.GroupBy(m => m.ParentName).ToList();
                <div class="layui-form-item">
                    <label class="layui-form-label">详情</label>
                    <div class="layui-input-block">
                        <table class="layui-table">
                            <thead>
                                @if (infoCustomFormExtendInfo.TableFields != null)
                                {
                                    if (myGroups.Count != parents.Count)
                                    {
                                        <tr>
                                            @foreach (var group in myGroups)
                                            {
                                                int children = group.Count();
                                                if (children == 1)
                                                {
                                                    <td rowspan="2" style="text-align:center;">@group.Key</td>
                                                }
                                                else
                                                {
                                                    <td colspan="@children" style="text-align:center;">@group.Key</td>
                                                }
                                            }
                                            <td rowspan="2" style="text-align:center;">#</td>
                                        </tr>
                                    }
                                }
                                <tr>
                                    @foreach (var item in infoCustomFormExtendInfo.TableFields)
                                    {

                                        string jsContent = string.Empty;
                                        if (myGroups.Count == parents.Count||item.ParentName != item.Name)
                                        {
                                            <th>@item.Name</th>
                                        }
                                         
                                    } 
                                </tr>
                            </thead>
                            <tbody>
                                @*@for (int i = 0; i < infoTableValues.RowValues.Count; i++)
                                {
                                    RowValue rowValue = infoTableValues.RowValues[i];
                                    if (rowValue.CellValues == null)
                                    {
                                        rowValue.CellValues = new Dictionary<string, string>();
                                    }
                                    <tr data-id="@i">
                                        @for (int j = 0; j < infoCustomFormExtendInfo.TableFields.Count; j++)
                                        {
                                            ExtendField infoExtendField = new ExtendField();
                                            infoExtendField = infoCustomFormExtendInfo.TableFields[j];
                                            var cellValue = string.Empty;
                                            if (rowValue.CellValues.ContainsKey(infoExtendField.Attribute))
                                            {
                                                infoExtendField.Value = rowValue.CellValues[infoExtendField.Attribute];
                                            }
                                            else
                                            {
                                                infoExtendField.Value = infoExtendField.DefaultValue;
                                            }
                                            <td>
                                                @infoExtendField.Value
                                            </td>
                                        } 
                                    </tr>
                                }*@
                            </tbody>
                        </table>
                    </div>
                </div>
            }

        }
    </div>
</div>
 
<script type="text/javascript">

    layui.use(['form', 'layedit', 'autocomplete', 'element', 'layer','laydate'], function () {
		form = layui.form;
        layer = layui.layer;
        element = layui.element;
        laydate = layui.laydate;
        @Html.Raw(tips)


    }); 

</script>
